<style lang="less">
  @import './login.less';
</style>

<template>


  <div class="login">
    <MyHeader></MyHeader>
    <div class="login-con">
      <Card icon="log-in" title="欢迎登录" :bordered="false">
        <div class="form-con">
          <login-form @on-success-valid="handleSubmit"></login-form>
          <p class="login-tip">输入任意用户名和密码即可</p>
        </div>
      </Card>
    </div>
  </div>
</template>

<script>
import LoginForm from "@/components/login-form"
import {login} from '@/utils/service'
import MyHeader from '@/components/MyHeader'
export default {
  components: {
    MyHeader,
    LoginForm
  },
  methods: {
    handleSubmit ({ userName, password,rememberMe }) {
      login(userName,password,data=>{
        if(data.code==100){
          this.$Message.success('登录成功');
          window.sessionStorage.setItem('user', JSON.stringify(data.user))
          this.$store.commit("setUser",data.user)

          //保存7天自动登录的凭据
          if(rememberMe){
            this.$cookies.set("rememberMe",JSON.stringify({
              username:userName,
              password:password
            }),60*60*24*7)
          }

          this.$router.push("/")
        }else{
          this.$Message.warning(data.msg);
        }
      })
    }
  }
}
</script>

<style>

</style>
